<?php

namespace App\Http\Controllers\Admin;

use App\Http\Model\Admin;
use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Input;

require_once 'App\Org\code\Code.class.php';

class LoginController extends CommonController
{
    /*
     * 登入操作
     */
    public function Login()
    {
        if ($input = Input::all()) {
            $code = new \Code;
            $_code = $code->get();
            if (strtoupper($input['code']) != $_code) {
                return back()->with('error', '验证码错误!')->withInput();
            }
            $db = Admin::first();
            $depass = Crypt::decrypt($db->password);
            if ($input['username'] != $db->username || $input['password'] != $depass) {
                return back()->with('error', '帐号或者密码错误');
            }
            session(['uid'=>$db->uid,'username'=>$db->username]);
            return redirect('admin/index');
        } else {
            return view('admin.login');
        }


    }
    /*
     * 退出操作
     */
    public function Logout(){
        session(['uid'=>null,'username'=>null]);
        return redirect('admin/login');
    }
/*
 * 获取验证码
 */
    public function getCode()
    {
        $code = new \Code;
        $code->make();
    }


}
